package org.example;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}
class Solution {
    //abbaca
    //ca
    public String removeDuplicates(String s) {
        StringBuilder sb = new StringBuilder();
        sb.append(s.charAt(0));
        for(int i = 1; i < s.length(); i++){
            //判断当前字符与栈顶元素是否相等
            int top = sb.length() - 1;
            if(top >= 0 && sb.charAt(top) == s.charAt(i)) sb.deleteCharAt(top);
            else sb.append(s.charAt(i));//不相等加入到栈顶
        }
        return sb.toString();
    }
}